//
//  B_ActivityPictureView.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/8/11.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "B_ActivityPictureView.h"
#import "B_ActivityPictureTVC.h"
#import "B_ActivityPictureModel.h"

@implementation B_ActivityPictureView

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor color_main_background_color];
        [self addSubview:self.tableView];
        [self setTableViewFrameWithTop:0 left:0 right:0 bottom:0];
        [self.tableView registerNib:[UINib nibWithNibName:@"B_ActivityPictureTVC" bundle:nil] forCellReuseIdentifier:@"B_ActivityPictureTVC"];
        [self setTableViewBlock];
    }
    return self;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


- (void) setTableViewBlock {
    WeakSelf(weSelf, self);
    self.numberOfSectionsBlock = ^NSInteger(UITableView *tableView) {
        return weSelf.dataArray.count;
    };
    self.tableView.pagingEnabled = YES;
    /// 组里的个数
    self.numberOfRowsBlock = ^NSInteger(UITableView *tableView, NSInteger section) {
        return 1;
    };
    self.viewForFooterBlock = ^UIView *(UITableView *tableView, NSInteger section) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        view.backgroundColor = [UIColor color_main_background_color];
        return view;
    };
    self.viewForHeaderBlock = ^UIView *(UITableView *tableView, NSInteger section) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        view.backgroundColor = [UIColor color_main_background_color];
        return view;
    };
    self.heightForFooterBlock = ^CGFloat(UITableView *tableView, NSInteger section) {
        return 0.1;
    };
    self.heightForHeaderBlock = ^CGFloat(UITableView *tableView, NSInteger section) {
        return 0.1f;
    };
    self.heightForRowBlock = ^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
        return tableView.bounds.size.height;
    };
    self.cellForRowBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
        
        ///TODO:在这里取模型赋值
        // TODO:在这里加载数据
        if (weSelf.dataArray.count - indexPath.section == 3) {
            if (weSelf.activityPictureLoadMore) {
                weSelf.activityPictureLoadMore();
            }
        }
        if (weSelf.dataArray.count - indexPath.section == 1) {
            //TODO:弹出toast 没有数据了
        }
        
        B_ActivityPictureModel * model = weSelf.dataArray[indexPath.section];
        
        ///TODO:在这里取模型赋值
        B_ActivityPictureTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_ActivityPictureTVC" forIndexPath:indexPath];
        [cell.B_IconImage sd_setImageWithURL:[NSURL URLWithString:model.portrait]];
        [cell.B_logoImageView setUsetType:model.userType];
        [cell.B_ImageView sd_setImageWithURL:[NSURL URLWithString:model.activityCover]];
        [cell.B_sexImageView mainpageSetSex:model.sex];
        cell.B_userName.text = model.nickName;
        cell.B_cityName.text = model.city;
        cell.B_ageLabel.text = [NSString stringWithFormat:@"%@岁", safeValue1(model.age)];
        cell.B_priceLabel.text = [NSString stringWithFormat:@"¥%@", safeValue1(model.applyPrice)];
        cell.B_title.text = model.activityTitle;
        cell.B_contentLabel.text = model.activityInfo;
        return cell;
    };
}

@end
